package org.hzero.order.api.controller.v1;

/**
 * @author xiuiqng.Yang-Estelle-양수청
 * @date 2019/8/7 8:56
 */

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.hzero.core.util.Results;
import org.hzero.order.config.SwaggerTags;
import org.hzero.order.domain.entity.Item;
import org.hzero.order.domain.repository.ItemRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.choerodon.core.domain.Page;
import io.choerodon.core.iam.ResourceLevel;
import io.choerodon.mybatis.pagehelper.domain.PageRequest;
import io.choerodon.swagger.annotation.Permission;

/**
 * API接口
 */
@Api(tags = SwaggerTags.ITEM)
@RestController("itemController.v1")
@RequestMapping("/v1/{organizationId}/items")
public class ItemController {

    @Autowired
    private ItemRepository itemRepository;

    @ApiOperation(value = "根据物料编码和物料描述查询物料")
    @Permission(level = ResourceLevel.SITE, permissionLogin = true)
    @GetMapping
    public ResponseEntity<Page<Item>> queryCompanyList(
            @RequestParam String itemCode,
            String itemDescription,
            PageRequest pageRequest){
        Item item = new Item();
        item.setItemCode(itemCode);
        item.setItemDescription(itemDescription);
        return Results.success(itemRepository.pageItem(item, pageRequest));
    }

    @ApiOperation(value = "LOV选择物料编码(查询值集列表)")
    @Permission(level = ResourceLevel.SITE, permissionLogin = true)
    @GetMapping("/code")
    public ResponseEntity<Page<Item>> queryItemCode(PageRequest pageRequest){

        return Results.success(itemRepository.pageItem(new Item(), pageRequest));
    }
}
